islogin()
getUserInfo()
logout()
let groupData1 = {}
async function getData() {
    const res = await axios({
        url: '/dashboard',
        //在拦截器中设置了
        // headers: {
        //     Authorization: localStorage.getItem('token')
        // }
    })
    console.log(res)
    randerOverview(res.data.data.year)
    renderSalary(res.data.data.salaryData)
    initGroupChart(res.data.data.groupData)
    initSalaryPieChar(res.data.data.salaryData)
    initProvince(res.data.data.provinceData
    )
    groupData1 = res.data.data.groupData
    const { age, group_count, salary, student_count } = res.data.data.overview
    Object.keys(res.data.data.overview).forEach(item => {
        document.querySelector(`.${item}`).innerHTML = res.data.data.overview[item]
    })
}
getData()
const renderSalary = (salaryData) => {
    var myChart = echarts.init(document.getElementById('salary'));
    const option = {
        title: {
            text: '班级薪资分布',
            top: 20,
            left: 20
        },
        tooltip: {
            trigger: 'item'
        },
        legend: {
            bottom: '5%',
            left: 'center'
        },
        color: ['#fda224', '#5097ff', '#3abcfa', '#34d39a'],
        series: [
            {
                name: '班级薪资分布',
                type: 'pie',
                radius: ['55%', '70%'],
                avoidLabelOverlap: false,
                itemStyle: {
                    borderRadius: 10,
                    borderColor: '#fff',
                    borderWidth: 2
                },
                label: {
                    show: false,
                    position: 'center'
                },
                labelLine: {
                    show: false
                },
                data: salaryData.map(item => {
                    return {
                        value: item.g_count + item.b_count,
                        name: item.label
                    }
                    //[{value:'19+14',name:1-1.5万,}]
                })
            }
        ]
    };
    myChart.setOption(option)
}
const randerOverview = (year) => {
    var myChart = echarts.init(document.getElementById('main'));
    option = {
        title: {
            text: '2022全学科薪资走势',
            top: 20,
            left: 20
        },
        grid: {
            top: '20%',
            left: '15%'
        },
        lengend: ['工资'],
        xAxis: {
            data: year.map(item => item.month),
            axisLine: {
                lineStyle: {
                    color: 'pink',
                    type: 'dashed'
                }
            },
        },
        yAxis: {
            splitLine: {
                lineStyle: {
                    color: ['red', 'pink', 'yellow'],
                    type: 'dashed'
                }
            },
        },
        series: [
            {
                name: '工资',
                data: year.map(item => item.salary),
                type: 'line',
                symbolSize: 10,
                smooth: true,
                lineStyle: {
                    width: 6,
                    color: {
                        type: 'linear',
                        x: 0,
                        y: 0,
                        x2: 1,
                        y2: 1,
                        colorStops: [{
                            offset: 1, color: '#5d77f0'
                        }, {
                            offset: .75, color: '#5d77f0'
                        }, {
                            offset: 0, color: '#50adff'
                        }]
                    }
                },
                areaStyle: {
                    color: {
                        type: 'linear',
                        x: 0,
                        y: 0,
                        x2: 0,
                        y2: 1,
                        colorStops: [{
                            offset: 0, color: '#4d95ee' // 0% 处的颜色
                        }, {
                            offset: 1, color: '#fff' // 100% 处的颜色
                        }],
                        global: false // 缺省为 false
                    }
                }
            }
        ]
    }
    option2 = {
        title: {
            text: '2022全学科薪资走势'
        },
        tooltip: {},
        lengend: ['工资'],
        xAxis: {
            data: year.map(item => item.month),
        },
        yAxis: {
            splitLine: {
                lineStyle: {
                    color: ['red', 'pink', 'yellow'],
                    type: 'dashed'
                }
            },
        },
        series: [
            {
                name: '工资',
                data: year.map(item => item.salary),
                type: 'line',
                symbolSize: 0,
                smooth: true,
                lineStyle: {
                    color: 'darkred',
                    width: 8
                },
                grid: {
                    left: '20%'
                },
                areaStyle: {
                    color: {
                        type: 'linear',
                        x: 0,
                        y: 0,
                        x2: 0,
                        y2: 1,
                        colorStops: [{
                            offset: 0, color: '#610000'
                        }, {
                            offset: 0.3, color: '#610000'
                        }, {
                            offset: 0.5, color: '#8B0000'
                        }, {
                            offset: 0.7, color: '#FF4D4D'
                        }, {
                            offset: 1, color: '#FFB3B3'
                        }],
                        global: false
                    }
                }
            }
        ]
    }
    myChart.setOption(option)
}
const initGroupChart = (data, n = 1) => {
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('lines'));
    const option = {
        legend: {},
        tooltip: {},
        dataset: {
            source: [
                ['product', '2015', '2016', '2017'],
                ['Matcha Latte', 43.3, 85.8, 93.7],
                ['Milk Tea', 83.1, 73.4, 55.1],
                ['Cheese Cocoa', 86.4, 65.2, 82.5],
                ['Walnut Brownie', 72.4, 53.9, 39.1]
            ]
        },
        xAxis: { type: 'category', data: data[n].map(item => item.name), },
        yAxis: {},
        series: [
            {
                type: 'bar',
                data: data[n].map(item => item.hope_salary),
            },
            {
                type: 'bar',
                data: data[n].map(item => item.salary),
            }],
        color: [
            {
                type: 'linear',
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [{
                    offset: 0, color: '#3fe9ac' // 0% 处的颜色
                }, {
                    offset: 1, color: '#d5fbed' // 100% 处的颜色
                }],
                global: false // 缺省为 false
            },
            {
                type: 'linear',
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [{
                    offset: 0, color: '#51aeff' // 0% 处的颜色
                }, {
                    offset: 1, color: '#cee5fa' // 100% 处的颜色
                }],
                global: false // 缺省为 false
            }
        ]
    };
    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
}
document.querySelector('#btns').addEventListener('click', (e) => {
    /* 点击图表切换 */
    initGroupChart(groupData1, e.target.innerText)
    /* 高亮切换 */
    if (!e.target.classList.contains('btn-blue')) {
        document.querySelector('.btn-blue').classList.remove('btn-blue')
        e.target.classList.add('btn-blue')
    }
})
const initSalaryPieChar = (salaryData) => {
    const dom = document.querySelector('#gender')
    const myChart = echarts.init(dom)
    const option = {
        tooltip: {
            trigger: 'item'
        },
        color: ['#fda224', '#5097ff', '#3abcfa', '#34d39a'],
        title: [
            {
                text: '男女薪资分布',
                left: 10,
                top: 10,
                textStyle: {
                    fontSize: 16
                }
            },
            {
                text: '男生',
                left: '50%',
                top: '45%',
                textStyle: {
                    fontSize: 12
                },
                textAlign: 'center'
            },
            {
                text: '女生',
                left: '50%',
                top: '85%',
                textStyle: {
                    fontSize: 12
                },
                textAlign: 'center'
            }
        ],
        series: [
            {
                type: 'pie',
                radius: ['20%', '30%'],
                center: ['50%', '30%'],
                data: salaryData.map(v => {
                    return { value: v.b_count, name: v.label }
                })
            },
            {
                type: 'pie',
                radius: ['20%', '30%'],
                center: ['50%', '70%'],
                data: salaryData.map(v => {
                    return { value: v.g_count, name: v.label }
                })
            }
        ]
    }
    myChart.setOption(option)
}
function initProvince(provinceData) {
    // console.log(provinceData)
    const dom = document.querySelector('#map')
    const myEchart = echarts.init(dom)
    const dataList = [
        { name: '南海诸岛', value: 0 },
        { name: '北京', value: 0 },
        { name: '天津', value: 0 },
        { name: '上海', value: 0 },
        { name: '重庆', value: 0 },
        { name: '河北', value: 0 },
        { name: '河南', value: 0 },
        { name: '云南', value: 0 },
        { name: '辽宁', value: 0 },
        { name: '黑龙江', value: 0 },
        { name: '湖南', value: 0 },
        { name: '安徽', value: 0 },
        { name: '山东', value: 0 },
        { name: '新疆', value: 0 },
        { name: '江苏', value: 0 },
        { name: '浙江', value: 0 },
        { name: '江西', value: 0 },
        { name: '湖北', value: 0 },
        { name: '广西', value: 0 },
        { name: '甘肃', value: 0 },
        { name: '山西', value: 0 },
        { name: '内蒙古', value: 0 },
        { name: '陕西', value: 0 },
        { name: '吉林', value: 0 },
        { name: '福建', value: 0 },
        { name: '贵州', value: 0 },
        { name: '广东', value: 0 },
        { name: '青海', value: 0 },
        { name: '西藏', value: 0 },
        { name: '四川', value: 0 },
        { name: '宁夏', value: 0 },
        { name: '海南', value: 0 },
        { name: '台湾', value: 0 },
        { name: '香港', value: 0 },
        { name: '澳门', value: 0 },
    ]

    // 筛选数据
    dataList.forEach(item => {
        const res = provinceData.find(v => {
            return v.name.includes(item.name)
        })
        // console.log(res)
        // 数据赋值
        if (res !== undefined) {
            item.value = res.value
        }
    })
    // console.log(dataList)

    const option = {
        title: {
            text: '籍贯分布',
            top: 10,
            left: 10,
            textStyle: {
                fontSize: 16,
            },
        },
        tooltip: {
            trigger: 'item',
            formatter: '{b}: {c} 位学员',
            borderColor: 'transparent',
            backgroundColor: 'rgba(0,0,0,0.5)',
            textStyle: {
                color: '#fff',
            },
        },
        visualMap: {
            min: 0,
            max: 6,
            left: 'left',
            bottom: '20',
            text: ['6', '0'],
            inRange: {
                color: ['#ffffff', '#0075F0'],
            },
            show: true,
            left: 40,
        },
        geo: {
            map: 'china',
            roam: false,
            zoom: 1.0,
            label: {
                normal: {
                    show: true,
                    fontSize: '10',
                    color: 'rgba(0,0,0,0.7)',
                },
            },
            itemStyle: {
                normal: {
                    borderColor: 'rgba(0, 0, 0, 0.2)',
                    color: '#e0ffff',
                },
                emphasis: {
                    areaColor: {
                        type: 'linear',
                        x: 0,
                        y: 0,
                        x2: 0,
                        y2: 1,
                        colorStops: [{
                            offset: 0, color: '#610000'
                        }, {
                            offset: 0.3, color: '#610000'
                        }, {
                            offset: 0.5, color: '#8B0000'
                        }, {
                            offset: 0.7, color: '#FF4D4D'
                        }, {
                            offset: 1, color: '#FFB3B3'
                        }],
                        global: false
                    },
                    shadowOffsetX: 0,
                    shadowOffsetY: 0,
                    shadowBlur: 20,
                    borderWidth: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)',
                },
            },
        },
        series: [
            {
                name: '籍贯分布',
                type: 'map',
                geoIndex: 0,
                data: dataList,
            },
        ],
    }
    myEchart.setOption(option)
}



